#include <iostream>
#include <queue>
using namespace std;

int n,a[35],flag = 0;
queue<pair<int,int>> q;

signed main()
{
    cin>>n;
    for(int i=0;i<n;i++)    cin>>a[i];
    q.push({0,n-1});
    while(!q.empty()){
        int l = q.front().first,r = q.front().second;
        q.pop();
        if(l>r)    continue;
        int mina = 0x3f3f3f,mini;
        for(int i=l;i<=r;i++){
            if(a[i]<mina){
                mina = a[i];
                mini = i;
            }
        }
        if(flag)    cout<<" ";
        flag = 1;
        cout<<a[mini];
        q.push({l,mini-1});
        q.push({mini+1,r});
    }
    return 0;
}
